apiready = function() {
    seajs.use(['../../V', "../../api", "../../jquery", "../../app", "../../service"], function(V, $api, $, app, service) {

        var vm = {
            el: '.container',
            data: {
                order_id: '',
                number: '',
                list: '',
                dataList: [],
            },
            mounted: function() {

            },
            methods: {
                viewExpress: function(callback) {
                    var that = this;
                    var unionid = $api.getStorage("shop_unionid"); // 用户id

                    app.ajax(service['buyViewExpress'], {
                            data: {
                                values: {
                                    unionid: unionid,
                                    order_id: this.order_id
                                }
                            }
                        },
                        function(res) {
                            if (res.code) {
                                alert("错误代码code：" + res.code + "\n错误信息：" + res.message)
                            } else {
                                callback(res)
                                console.log("获取商品列表成功!");
                            }
                        });
                },
                //--复制
                shopFlowCopy: function(number) {
                    var that = this;
                    var clipBoard = api.require('clipBoard');
                    this.number = number;
                    clipBoard.set({
                        value: that.number
                    }, function(ret, err) {
                        if (ret) {
                            // alert(JSON.stringify(ret));
                            api.toast({
                                msg: '已复制物流单号：' + that.number,
                                duration: 2000,
                                location: 'middle'
                            });

                        } else {
                            alert(JSON.stringify(err));
                        }
                    });
                },
                dialphone: function(event) {
                    if (event.target.nodeName === 'SPAN') {
                        api.call({
                            type: 'tel_prompt',
                            number: event.target.innerHTML
                        });
                    }

                },
            },
            created: function() {
                var that = this;
                this.order_id = api.pageParam.order_id;

                this.viewExpress(function(res) {
                    that.list = res.data;
                    that.dataList = res.data.content.data;

                    if (that.dataList) {
                        for (var i = 0; i < that.dataList.length; i++) {

                            var phone_str = that.dataList[i].context;
                            console.log(phone_str);
                            console.log(typeof phone_str);
                            //--手机号码
                            var reg_phone = /\b(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])\d{8}/g;
                            var phone_num = phone_str.match(reg_phone);
                            if (Array.isArray(phone_num)) {
                                var phone_html = "[<span class='dial'>" + phone_num[0] + "</span>]";
                            } else {
                                var phone_html = "[<span class='dial'>" + phone_num + "</span>]";
                            }
                            phone_str = phone_str.replace(reg_phone, phone_html);
                            //--电话号码
                            var reg_tel = /\B(\d{3,4}-)\d{7,8}/g;
                            var tel_num = phone_str.match(reg_tel);
                            var tel_html = "[<span class='dial'>" + tel_num + "</span>]";
                            phone_str = phone_str.replace(reg_tel, tel_html);

                            that.dataList[i].context = phone_str;
                        }
                    } else {
                        api.toast({
                            msg: '暂无物流信息',
                            duration: 2000,
                            location: 'bottom'
                        });

                    }

                    console.log(JSON.stringify(that.dataList));
                });
            }
        };

        var even = function() {
          $(".header-btn").on('click', function() {
              api.closeWin();
          })
        };
        var newVue = new Vue(vm);
        even();

    })
}
